//
//  MenuCellWithSty.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 16/9/28.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "MenuCellWithSty.h"
#import "Masonry.h"
#import "MenuModel.h"

#define STYLE0 @"0" // 主项目风格
#define STYLE1 @"1" // 学员端风格

@implementation MenuCellWithSty

-(id)UIStyle:(NSString *)style andCollectionView:(UICollectionView *)collectionView withIndexPath:(NSIndexPath *)indexPath andModel:(id)dic withNum:(NSInteger)num{
    if ([style isEqualToString:STYLE0]) {
        return [self style0Dic:dic andCollectionView:collectionView withIndexPath:indexPath withNum:num];
    }else{
        return [self style1Dic:dic andCollectionView:collectionView withIndexPath:indexPath];
    }
}

-(id)style0Dic:(MenuModel *)model andCollectionView:(UICollectionView *)collectionView withIndexPath:(NSIndexPath *)indexPath withNum:(NSInteger)num{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    ThingsCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
    cell.titleLa.text = @"";
    cell.titleLa.numberOfLines = 0;
//    int i = arc4random() % 4+1;
    int i = indexPath.row;
    
    if(model.menuName){
        
        NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", model.menuName];
        if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
            [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
        }
        
        cell.titleLa.text = strMenuName;
        
//        if(num==4){
//        cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d", i+1]];
//        }else{
//          cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d", 5+i]];
//        }
        cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld", (num+indexPath.row)%20+1]];
        //         = [UIImage imageNamed:@"形状-9"];
        [cell changeRect:NO];
        
    }else{
        [cell changeRect:YES];
        
        
    }
    
    return cell;
    

}

-(id)style1Dic:(NSDictionary *)dic andCollectionView:(UICollectionView *)collectionView withIndexPath:(NSIndexPath *)indexPath{
    static NSString * CellIdentifier = @"UICollectionViewCell";
    FounctionCollectionCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    
    cell.titleLa.text = @"";
    cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@""]];
    
    
    if(dic.allKeys.count>1){
        
        NSMutableString *strMenuName = [NSMutableString stringWithFormat:@"%@", [dic objectForKey:@"menuName"]];
        if ([strMenuName rangeOfString:@"手机端"].location != NSNotFound) {
            [strMenuName replaceCharactersInRange:[strMenuName rangeOfString:@"手机端"] withString:@""];
        }
        
        cell.titleLa.text = strMenuName;
        
//        int x = arc4random() % 7;
        if(indexPath.row>11){
            int x = [self getRandomNumber:1 to:12];
            
            cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"分类000%ld", x]];
        }else{
          cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"分类000%ld", (long)indexPath.row+1]];
        }
//        cell.titleImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"分类000%ld", (long)indexPath.row+1]];
        
        [cell changeRect:NO];
        
    }else{
        [cell changeRect:YES];
        cell.titleImg2.image =[UIImage imageNamed:[dic objectForKey:@"img"]];
    }
    [cell changeLine:indexPath];
    return cell;
}


-(int)getRandomNumber:(int)from to:(int)to

{
    
    return (int)(from + (arc4random() % (to -from + 1)));
    
}

@end
